package com.ccx.coachsite.webimage;

import com.ccx.coachsite.bus.JSONTextUtils;
import com.ccx.coachsite.http.BitmapProgress;
import com.ccx.coachsite.http.ProgressListener;
import com.ccx.coachsite.http.UrlConfig;
import com.ccx.coachsite.util.StringUtil;

import android.graphics.Bitmap;
import android.view.View;

public class ImageLoader {

	public static String getFileNameMD5(String str) {
		return HttpImage.getFileNameMD5(str);
	}

	public static String getFilePath(String url) {
		return HttpImage.getFilePath(url);
	}

	// 加载图片，统一入口
	public static Bitmap loadBitmap(final String url,
			final ProgressListener<BitmapProgress> listener) {

		return HttpImage.loadBitmap(url, listener);
	}

	/**
	 * 下载图片，并设置相应的view
	 * 
	 * @param url
	 * @param view
	 */
	public static void loadBitmap(final String url, final View view) {
		if (!JSONTextUtils.isEmpty(url)) {
			String url1 = url;
			if (!url.startsWith("http"))
				url1 = UrlConfig.ImageBaseUrl + url;
			HttpImage.loadBitmap(url1, view);
		}
	}

	// 从SD卡缓存找图片
	public static Bitmap getBitmapFromSdCard(String fileName) {

		return HttpImage.getBitmapFromSdCard(fileName);
	}

	// 从SD卡缓存找图片
	public static Bitmap getBitmapFromSdCard(String fileDir, String fileName) {
		return HttpImage.getBitmapFromSdCard(fileDir, fileName);
	}

	public static void getBitmapFromUrl(final String url,
			final String cacheKey,
			final ProgressListener<BitmapProgress> listener) {

		HttpImage.getBitmapFromUrl(url, cacheKey, listener);
	}

	public static Bitmap decodeFile(String filePath, int quanlity) {
		return HttpImage.decodeFile(filePath, quanlity);
	}

	// clear overdue files
	public static void clearOverdue() {
		HttpImage.clearOverdue();
	}

	// clear all cache file
	public static void clearCache() {
		HttpImage.clearCache();
	}

}
